package com.zksk.portal.controller.manual;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zksk.admin.api.RemoteDictService;
import com.zksk.admin.api.domain.SysDictData;
import com.zksk.common.core.constant.PortalConstants;
import com.zksk.common.core.constant.SecurityConstants;
import com.zksk.common.core.domain.R;
import com.zksk.common.core.web.controller.BaseController;
import com.zksk.common.log.annotation.Log;
import com.zksk.common.log.enums.BusinessType;
import com.zksk.admin.api.domain.portal.dto.ManualDto;
import com.zksk.admin.api.domain.portal.vo.ManualVo;
import com.zksk.portal.domain.vo.LeftNavMenuVo;
import com.zksk.portal.service.manual.ManualService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;


@Slf4j
@RequestMapping("/manual/")
@RestController
@Api(tags = "操作手册相关接口")
public class ManualController extends BaseController
{

    @Autowired
    private ManualService manualService;

    @Autowired
    private RemoteDictService remoteDictService;

    /**
     * 操作指南左侧菜单
     *
     * @return
     */
    @GetMapping("nav")
    @ApiOperation(value = "获取操作指南左侧菜单")
    public R<List<LeftNavMenuVo>> navMenu()
    {
        List<SysDictData> dictDataByCode = remoteDictService
                .getDictDataByCode(PortalConstants.GUIDE_DICT_CODE, SecurityConstants.INNER).getData();

        List<LeftNavMenuVo> resultList = dictDataByCode.stream().map( item ->
        {
            LeftNavMenuVo leftNavMenuVo = new LeftNavMenuVo();
            leftNavMenuVo.setValue(item.getDictValue());
            leftNavMenuVo.setLabel(item.getDictLabel());
            leftNavMenuVo.setType(item.getDictType());
            leftNavMenuVo.setDesc(item.getRemark());
            return leftNavMenuVo;
        }).collect(Collectors.toList());

        return R.ok(resultList, "菜单获取成功");
    }

    @PostMapping("selectList")
    @Log(title = "查询操作指南信息", businessType = BusinessType.SELECT)
    @ApiOperation(value = "分页条件查询操作指南")
    public R<Page<ManualVo>> selectList(@RequestBody ManualDto manualDto)
    {
        return manualService.selectList(manualDto);
    }

    @GetMapping("getById/{id}")
    @Log(title = "查询操作指南信息", businessType = BusinessType.SELECT)
    @ApiOperation(value = "根据ID查询")
    public R<ManualVo> selectList(@PathVariable Long id)
    {
        return manualService.selectById(id);
    }

}
